﻿
/*################################################################ AUTHOR - SAVITHRI MANNAZHIMANA BABU ################################################################ */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntityObjects;
using BAL.Controller;

namespace PresentationLayer.View.DepartmentRepresentative
{
    public partial class ChangeCollectionPoint : System.Web.UI.Page
    {
        int collectionId;
        string depId;
        ChangeCollectionPointControl cpControl;        
        CollectionPoint collectionPoint;
        Department dept;
        string empId;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                Employee currentuser = (Employee)Session["CurrentUser"];
                empId = currentuser.EmpId;
                //empId = "10043";
                cpControl = new ChangeCollectionPointControl();
                dept = new Department();
                dept = cpControl.getDepartmentByRepId(empId);

                if (dept != null)
                {
                    collectionId = Convert.ToInt32(dept.CollectionId);
                    collectionPoint = new CollectionPoint();
                    collectionPoint = cpControl.selectCollectionPoint(collectionId);
                    lblCollectionPoint.Text = collectionPoint.Place.ToString();
                }

                List<CollectionPoint> cp_list = new List<CollectionPoint>();
                cp_list = cpControl.selectAllCollectionPoint();
                ddNewCollectionPoint.DataSource = cp_list;
                ddNewCollectionPoint.DataTextField = "place";
                ddNewCollectionPoint.DataBind();
                
            }
        }

        protected void ddNewCollectionPoint_SelectedIndexChanged1(object sender, EventArgs e)
        {
           
        }

        protected void btnChange_Click1(object sender, EventArgs e)
        {           
            Employee currentuser = (Employee)Session["CurrentUser"];
            empId = currentuser.EmpId;
            //empId = "10043";
            dept = new Department();
            cpControl = new ChangeCollectionPointControl();
            dept = cpControl.getDepartmentByRepId(empId);
            if (dept != null)
            {
                dept.CollectionId = ddNewCollectionPoint.SelectedIndex + 1;
                depId = dept.DeptId.ToString();
            }
            cpControl.updateDepartment(dept, depId);
            Response.Redirect("ChangeCollectionPoint.aspx");
        }

        protected void btnCancel_Click1(object sender, EventArgs e)
        {
            //Response.Redirect("DeptRepresentative.Master");
        }

    }
}

